package com.xinian.springclud_demo.common;

import com.xinian.springclud_demo.enums.StatusEnum;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    /**
     * 是否成功
     */
    private Boolean success;
    /**
     * 返回消息
     */
    private String message;
    /**
     * 返回编码
     */
    private Integer code;
    /**
     * 返回数据
     */
    private Object data;


    /**
     * 成功
     *
     * @return
     */
    public static Result success() {
        return success(null);
    }

    /**
     * 成功
     * @param data
     * @return
     */
    public static Result success(Object data) {
        Result rb = new Result();
        rb.setCode(StatusEnum.SUCCESS.getErrorCode());
        rb.setMessage(StatusEnum.SUCCESS.getErrorMsg());
        rb.setData(data);
        return rb;
    }


    /**
     * 失败
     */
    public static Result error() {
        Result rb = new Result();
        rb.setCode(StatusEnum.FAIL.getErrorCode());
        rb.setMessage(StatusEnum.FAIL.getErrorMsg());
        rb.setData(null);
        return rb;
    }

    /**
     * 失败
     */
    public static Result error( String message) {
        Result rb = new Result();
        rb.setCode(-1);
        rb.setMessage(message);
        rb.setData(null);
        return rb;
    }

}
